package cn.cdeden.knowledge.dubbo;

import cn.cdeden.common.core.utils.MapstructUtils;
import cn.cdeden.common.core.utils.page.TableDataInfo;
import cn.cdeden.knowledge.api.domain.RemoteResourceService;
import cn.cdeden.knowledge.api.domain.dto.RemoteResourceQueryParam;
import cn.cdeden.knowledge.api.domain.vo.RemoteResourceTypeVo;
import cn.cdeden.knowledge.api.domain.vo.RemoteResourceVo;
import cn.cdeden.knowledge.domain.dto.SysResourceDto;
import cn.cdeden.knowledge.domain.dto.SysResourceQueryParam;
import cn.cdeden.knowledge.service.SysResourceService;
import cn.cdeden.knowledge.service.SysResourceTypeService;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@RequiredArgsConstructor
@Service
@DubboService
public class RemoteResourceServiceImpl implements RemoteResourceService {


    private final SysResourceService sysResourceService;


    @Override
    public TableDataInfo<RemoteResourceVo> query(RemoteResourceQueryParam query, Pageable pageable) {
        SysResourceQueryParam queryParam = MapstructUtils.convert(query, SysResourceQueryParam.class);
        TableDataInfo<SysResourceDto> sysResourceDtoTableDataInfo = sysResourceService.queryAll(queryParam, pageable);
        return MapstructUtils.convertTableDataInfo(sysResourceDtoTableDataInfo,RemoteResourceVo.class);
    }

    @Override
    public boolean insert(RemoteResourceVo resources) {
        SysResourceDto convert = MapstructUtils.convert(resources, SysResourceDto.class);
        return sysResourceService.insert(convert);
    }

    @Override
    public boolean updateById(RemoteResourceVo resources) {
        SysResourceDto convert = MapstructUtils.convert(resources, SysResourceDto.class);
        return sysResourceService.updateById(convert);
    }

    @Override
    public boolean deleteByIds(Set<Long> ids) {
        return sysResourceService.deleteByIds(ids);
    }
}
